#include "stdafx.h"
#include <boost/test/auto_unit_test.hpp>
#include "detail/bmock_in_arg_val.hpp"
#include "detail/bmock_test_control_tools.hpp"
#include <sstream>

namespace bmock {
	static const control_tools_ptr tl(new test_control_tools());
	static const char str_val[] = "ABCDEFG";
	static const char              name[] = "arg";

	BOOST_AUTO_TEST_CASE(test_print_in_const_str_arg_val) {
		const arg_val_ptr p_val(make_in_arg_val(name,str_val));
		const std::string      expected = "IN(\""+std::string(str_val)+"\")";
		std::ostringstream        os;

		BOOST_CHECK_NO_THROW(p_val->print(os));
		BOOST_CHECK_EQUAL(expected,os.str());
	}

	BOOST_AUTO_TEST_CASE(test_print_in_str_arg_val) {
		const arg_val_ptr p_val(make_in_arg_val(name,(char *)str_val));
		const std::string      expected = "IN(\""+std::string(str_val)+"\")";
		std::ostringstream        os;

		BOOST_CHECK_NO_THROW(p_val->print(os));
		BOOST_CHECK_EQUAL(expected,os.str());
	}

	BOOST_AUTO_TEST_CASE(test_print_in_const_unsigned_str_arg_val) {
		const arg_val_ptr p_val(make_in_arg_val(name,(const unsigned char *)str_val));
		const std::string      expected = "IN(\""+std::string(str_val)+"\")";
		std::ostringstream        os;

		BOOST_CHECK_NO_THROW(p_val->print(os));
		BOOST_CHECK_EQUAL(expected,os.str());
	}

	BOOST_AUTO_TEST_CASE(test_print_in_unsigned_str_arg_val) {
		const arg_val_ptr p_val(make_in_arg_val(name,(unsigned char *)str_val));
		const std::string      expected = "IN(\""+std::string(str_val)+"\")";
		std::ostringstream        os;

		BOOST_CHECK_NO_THROW(p_val->print(os));
		BOOST_CHECK_EQUAL(expected,os.str());
	}

	BOOST_AUTO_TEST_CASE(test_const_in_str_arg_val) {
		const arg_val_ptr p_val(make_in_arg_val(name,str_val));
		const arg_val_str expected(str_val,"");
		arg_checker       al(tl);
		bool              result = true;

		al.set_location(location(__FILE__,__LINE__+1));
		BOOST_CHECK_NO_THROW(result = p_val->validate(al,expected));
		BOOST_CHECK(!result);
		BOOST_CHECK_EQUAL(expected,p_val->get_value(al));
	}

	BOOST_AUTO_TEST_CASE(test_str_arg_val) {
		const arg_val_ptr p_val(make_in_arg_val(name,(char *)str_val));
		const arg_val_str expected(str_val,"");
		arg_checker       al(tl);
		bool              result = true;

		al.set_location(location(__FILE__,__LINE__+1));
		BOOST_CHECK_NO_THROW(result = p_val->validate(al,expected));
		BOOST_CHECK(!result);
		BOOST_CHECK_EQUAL(expected,p_val->get_value(al));
	}
}
